<template>
  <div>
    <el-row style="margin: 10px">
      <el-col>
        <el-col :span="4">
          <el-input v-model="searchPhone" placeholder="通过手机号搜索" clearable></el-input>
        </el-col>
        <el-col :span="4" style="margin-left: 10px">
          <el-input v-model="searchName" placeholder="通过用户名搜索" clearable></el-input>
        </el-col>
        <el-col :span="4" style="margin-left: 10px">
          <el-input v-model="searchRealName" placeholder="通过真实姓名搜索" clearable></el-input>
        </el-col>
        <el-col :span="3" style="margin-left: 20px">
          <el-button type="primary" @click="handleSearch">搜索</el-button>
        </el-col>
      </el-col>
    </el-row>
    <el-table :data="userData" style="width: 100%">
      <el-table-column label="手机号码"  align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.row.userPhone }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户名" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px" v-if="scope.row.username">{{ scope.row.username }}</span>
          <span style="margin-left: 10px" v-else>未注册</span>
        </template>
      </el-table-column>
      <el-table-column label="真实姓名" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px" v-if="scope.row.realName">{{ scope.row.realName }}</span>
          <span style="margin-left: 10px" v-else>未填写</span>
        </template>
      </el-table-column>
      <el-table-column label="是否登录成功" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px" v-if="scope.row.success === true">成功</span>
          <span style="margin-left: 10px; color: #F6416C" v-else>失败</span>
        </template>
      </el-table-column>
      <el-table-column label="登录时间" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px"><el-date-picker type="datetime" :value="scope.row.createTime" readonly></el-date-picker></span>
        </template>
      </el-table-column>
    </el-table>
    <el-col :span="12" :offset="14" style="margin-top: 20px">
      <el-pagination
        background
        layout="prev, pager, next, jumper, sizes"
        :current-page="page.currentPage"
        :total="page.total"
        :pager-count="5"
        :page-size="page.pageSize"
        :page-sizes="page.pageSizes"
        @current-change="pageChange"
        @size-change="sizeChange">
      </el-pagination>
    </el-col>
  </div>
</template>

<script>
import { getLoginList } from '@/api/loginManage'

export default {
  data() {
    return {
      userData: [],
      searchPhone: '',
      searchName: '',
      searchRealName: '',
      page: {
        pageSize: 5,
        pageSizes: [5, 10, 20, 40, 80],
        totalPage: 1,
        total: 0,
        currentPage: 1
      }
    }
  },
  computed: {},
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getLoginList({
        page: this.page.currentPage,
        limit: this.page.pageSize,
        searchPhone: this.searchPhone,
        searchName: this.searchName,
        searchRealName: this.searchRealName
      }).then((res) => {
        this.userData = JSON.parse(res.data.list)
        this.page.total = res.data.total
        this.page.totalPage = res.data.totalPage
      })
    },
    handleSearch() {
      this.currentPage = 1
      this.getList()
    },
    handleEdit(index, row) {
      console.log(index, row)
    },
    pageChange(page) {
      this.page.currentPage = page
      this.getList()
    },
    sizeChange(size) {
      this.page.pageSize = size
      this.getList()
    }
  }
}
</script>

<style scoped>

</style>
